﻿using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Reflection;
using Aspose.Slides;
//using Aspose.Slides.Animation;

namespace Helpers
{
    public static class PPTHelperOld
    {

        public static List<string> ConvertToImages(string pptfile, string savedirectory = "")
        {
            //pptfile = @"C:\games\足球产业互联网930汇报 - 副本.ppt";

            // 返回的图片绝对路径集合
            List<string> images = new List<string>();

            // 获取 Word 文件名称
            var pptname = System.IO.Path.GetFileNameWithoutExtension(pptfile);

            // 如果指定了保存路径，则使用传入的路径，否则在 Pdf 文件的同级创建同名文件夹当作保存路径
            savedirectory = string.IsNullOrWhiteSpace(savedirectory) ? System.IO.Path.GetDirectoryName(pptfile) : savedirectory;
            savedirectory = System.IO.Path.Combine(savedirectory, pptname);
            // 防止保存的路径不存在因此创建保存文件夹
            Directory.CreateDirectory(savedirectory);

            var pres = new Presentation(pptfile);

            int pptcount = pres.Slides.Count;
            for (int p = 0; p < pptcount; p++)
            {
                var item = pres.Slides[p];
                var imagefile = System.IO.Path.Combine(savedirectory, p + ".jpg");
                imagefile = System.IO.Path.Combine(savedirectory, p + "_" + "i" + ".jpg");
                item.GetThumbnail(2.0f, 2.0f).Save(imagefile);
                images.Add(imagefile);
            }

            return images;
        }

    }
}
